package api_day02;
/*
    字符串String类测试
 */
public class StringDemo1 {
    public static void main(String[] args) {
        String s1 = new String();
        String s2 = new String("");
        String s3 = new String(new char[]{'a', 'b', 'c', 'd'});
        String s4 = new String(new byte[]{97, 98, 99, 100});
        System.out.println(s1);
        System.out.println(s2);
        System.out.println(s3);
        System.out.println(s4);
        System.out.println("---------------------");
        //常量池测试
        System.out.println(s1 == s2);//false
        System.out.println(s2 == s3);//false
        System.out.println(s3 == s4);//false
        String s5 = "hi";
        String s6 = "hi";
        System.out.println(s5 == s6);//true

        //案例
        String str1 = "he";
        String str2 = "hello";
        String str3 = "he" + "llo"; //常量 + 常量 -> 常量一致 -> 常量池内拼接，然后匹配是否有相同的字符串，如果有则合并成一个
        String str4 = str1 + "llo"; //变量 + 常量 -> 常量不一致 -> 外部新生成一个对象存储拼接后的字符串
        //问下俩结果
        System.out.println(str2 == str3); //true
        System.out.println(str2 == str4); //false
    }
}
